package com.dingwei.superiordiary.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.bumptech.glide.Glide;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.adapter.adapter.CommodityDetailsEvaluationListAdapter;
import com.dingwei.superiordiary.adapter.easyViewHolder.ImgHolder;
import com.dingwei.superiordiary.app.MyApplication;
import com.dingwei.superiordiary.bean.CommodityDetailsBean;
import com.dingwei.superiordiary.bean.FindDetailsBean;
import com.dingwei.superiordiary.bean.GoodsCommentSuccessBean;
import com.dingwei.superiordiary.mvp.presenter.CommodityDetailsPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.dingwei.superiordiary.utils.ShareDialogUtils;
import com.dingwei.superiordiary.weight.SampleCoverVideo1;
import com.google.gson.Gson;
import com.jaeger.library.StatusBarUtil;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.decoration.SpaceDecoration;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.ColumValue;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.utils.DisplayUtil;
import com.lihao.baselibrary.utils.L;
import com.lihao.baselibrary.utils.NetWorkUtil;
import com.lihao.baselibrary.weight.MyRadioGroup;
import com.lihao.baselibrary.weight.TitleBar;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.shuyu.gsyvideoplayer.video.base.GSYVideoPlayer;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.Base;
import com.umeng.socialize.utils.SocializeUtils;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created time 2018/2/24.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class CommodityDetailsActivity extends BaseActivity implements Contract.CommodityDetailsView {
    CommodityDetailsPresenter commodityDetailsPresenter = new CommodityDetailsPresenter(this);
    @Bind(R.id.video_item_player)
    SampleCoverVideo1 videoItemPlayer;
    @Bind(R.id.img_content)
    ImageView imgContent;
    @Bind(R.id.rb_video)
    RadioButton rbVideo;
    @Bind(R.id.rb_img)
    RadioButton rbImg;
    @Bind(R.id.my_RadioGroup)
    MyRadioGroup myRadioGroup;
    @Bind(R.id.tv_content)
    WebView tvContent;
    @Bind(R.id.img_recyclerView)
    RecyclerView imgRecyclerView;
    @Bind(R.id.comment_recyclerView)
    RecyclerView commentRecyclerView;
    @Bind(R.id.tv_question)
    WebView tvQuestion;
    @Bind(R.id.data_layout)
    RelativeLayout dataLayout;
    @Bind(R.id.no_data_layout)
    RelativeLayout noDataLayout;
    @Bind(R.id.main_titleBar)
    TitleBar mainTitleBar;
    ImageView imageView;
    @Bind(R.id.tv_more)
    TextView tvMore;
    @Bind(R.id.ll_title)
    LinearLayout llTitle;
    @Bind(R.id.img_layout)
    RelativeLayout imgLayout;
    @Bind(R.id.ll_show_evaluation)
    LinearLayout llShowEvaluation;
    @Bind(R.id.btn_add_shopcart)
    SuperButton btnAddShopCart;
    @Bind(R.id.btn_pay)
    SuperButton btnPay;
    @Bind(R.id.ll_bottom)
    LinearLayout llBottom;
    @Bind(R.id.tv_look)
    TextView tvLook;
    @Bind(R.id.tv_like)
    TextView tvLike;
    @Bind(R.id.tv_collect)
    TextView tvCollect;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.no_net_btn)
    TextView noNetBtn;
    @Bind(R.id.no_net_layout)
    RelativeLayout noNetLayout;
    @Bind(R.id.scrollView)
    NestedScrollView scrollView;

    private CommodityDetailsEvaluationListAdapter mAdapter;
    private String id;
    private String key;
    private boolean isLike;
    private boolean isCollect;
    OrientationUtils orientationUtils;
    CommodityDetailsBean bean;
    private boolean isShare;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_commodity_details;
    }

    @Override
    protected void initData() {
        commodityDetailsPresenter.initData(id);
    }

    RecyclerArrayAdapter imgAdapter = new RecyclerArrayAdapter(BaseActivity.context) {
        @Override
        public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
            return new ImgHolder(parent);
        }
    };

    @Override
    protected void initView() {

        id = getIntent().getStringExtra("id");
        if (getIntent().getScheme() != null) {
            Intent intent1 = getIntent();
            Uri uri = intent1.getData();
            Log.e("test", "scheme: " + uri.getScheme());
            Log.e("test", "host: " + uri.getHost());
            Log.e("test", "port: " + uri.getPort());
            Log.e("test", "path: " + uri.getPath());
            Log.e("test", "queryString: " + uri.getQuery());
            Log.e("test", "queryParameter: " + uri.getQueryParameter("product_id"));
            id = uri.getQueryParameter("product_id");
            key = uri.getQueryParameter("key");
            isShare = true;
        } else {
            id = getIntent().getStringExtra("id");
        }

        WebSettings webSettings = tvContent.getSettings();
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setJavaScriptEnabled(true);//支持js
        tvContent.addJavascriptInterface(new JiaoHu(), "wjj");

        StatusBarUtil.setTranslucentForImageView(this, 30, null);

        GridLayoutManager layoutManager = new GridLayoutManager(BaseActivity.context, 3);
        layoutManager.setSpanSizeLookup(imgAdapter.obtainGridSpanSizeLookUp(3));
        SpaceDecoration itemDecoration = new SpaceDecoration((int) DisplayUtil.dip2px(BaseActivity.context, 8));//参数是距离宽度
        itemDecoration.setPaddingEdgeSide(true);//是否为左右2边添加padding.默认true.
        itemDecoration.setPaddingStart(true);//是否在给第一行的item添加上padding(不包含header).默认true.
        itemDecoration.setPaddingHeaderFooter(false);//是否对Header于Footer有效,默认false.
        imgRecyclerView.setLayoutManager(layoutManager);
        imgRecyclerView.setAdapter(imgAdapter);
        imgRecyclerView.setNestedScrollingEnabled(false);
        imgRecyclerView.addItemDecoration(itemDecoration);


        LinearLayoutManager linlayoutManager = new LinearLayoutManager(context);
        linlayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        commentRecyclerView.setLayoutManager(linlayoutManager);
        commentRecyclerView.setNestedScrollingEnabled(false);
        mAdapter = new CommodityDetailsEvaluationListAdapter(BaseActivity.context);
        commentRecyclerView.setAdapter(mAdapter);


        mainTitleBar.setOnMenuListener(new TitleBar.OnMenuListener() {
            @Override
            public void onMenuClick() {
                commodityDetailsPresenter.showSortPopupWindow(mainTitleBar.getMenu(), isLike, isCollect);
            }
        });

        mAdapter.setReplyInterface(new CommodityDetailsEvaluationListAdapter.ReplyInterface() {
            @Override
            public void reply(int position) {
                if (!BaseActivity.value.getIsLogin()) {
                    intent = new Intent(BaseActivity.context, LoginActivity.class);
                    startActivity(intent);
                    return;
                }
                CommodityDetailsBean.DataBean.CommentBean bean = mAdapter.getItem(position);
                commodityDetailsPresenter.showEvaluationDialog(id, bean.id, position);
            }

            @Override
            public void likes(int position) {
                CommodityDetailsBean.DataBean.CommentBean bean = mAdapter.getItem(position);
                commodityDetailsPresenter.commentLike(bean.id, position);
            }

            @Override
            public void more(int position) {
                CommodityDetailsBean.DataBean.CommentBean bean = mAdapter.getItem(position);
                intent = new Intent(BaseActivity.context, MoreReplyActivityGoods.class);
                intent.putExtra("id", id);
                intent.putExtra("pid", bean.id);
                startActivity(intent);
            }
        });

    }

    public class JiaoHu {
        @JavascriptInterface
        public void showImg(String list, int position) {

            L.e(new Gson().toJson(list).toString());
            try {
                JSONArray jsonArray = new JSONArray(list);
                List<String> list1 = new ArrayList<>();
                for (int i = 0; i < jsonArray.length(); i++) {
                    list1.add(jsonArray.getString(i));
                }
                Intent intent = new Intent();
                intent.setClass(context, PhotoDetailsActivity.class);
                intent.putExtra("position", position);
                intent.putExtra("img", (Serializable) list1);
                startActivity(intent);
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void initListener() {
        myRadioGroup.setOnCheckedChangeListener(new MyRadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(MyRadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_video) {
                    GSYVideoManager.onResume();
                    imgContent.setVisibility(View.GONE);
                    videoItemPlayer.setVisibility(View.VISIBLE);
                    tvName.setVisibility(View.GONE);
                    tvLike.setVisibility(View.GONE);
                    tvCollect.setVisibility(View.GONE);
                    tvLook.setVisibility(View.GONE);
                } else {
                    GSYVideoManager.onPause();
                    imgContent.setVisibility(View.VISIBLE);
                    tvName.setVisibility(View.VISIBLE);
                    tvLike.setVisibility(View.VISIBLE);
                    tvCollect.setVisibility(View.VISIBLE);
                    tvLook.setVisibility(View.VISIBLE);
                    videoItemPlayer.setVisibility(View.GONE);
                }
            }
        });
        imgAdapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                List<String> paths = new ArrayList<String>();
                for (int i = 0; i < bean.data.image.size(); i++) {
                    paths.add(bean.data.image.get(i).og);
                }

                Intent intent = new Intent();
                intent.setClass(context, PhotoDetailsActivity.class);
                intent.putExtra("position", position);
                intent.putExtra("img", (Serializable) paths);
                startActivity(intent);
            }
        });

        scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
            @Override
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                if (videoItemPlayer != null && videoItemPlayer.getHeight() > 0) {
                    llTitle.setBackgroundColor(getResources().getColor(R.color.white));
                    int height = videoItemPlayer.getHeight();
                    if (scrollY < height) {
                        int alpha = (int) (new Float(scrollY) / new Float(height) * 200);
                        Log.e("yy", "" + alpha);
                        llTitle.getBackground().mutate().setAlpha(alpha);
                        if (alpha < 150) {
                            mainTitleBar.setTitleText("");
                            mainTitleBar.setBackImageResource(R.drawable.white_back);
                            mainTitleBar.setMenuImageResource(R.drawable.image_diandia);
                        } else {
                            mainTitleBar.setTitleText("商品详情");
                            mainTitleBar.setBackImageResource(R.drawable.img_back);
                            mainTitleBar.setMenuImageResource(R.drawable.pic15);

                        }
                    } else {
                        llTitle.getBackground().mutate().setAlpha(255);
                    }
                } else {
                    llTitle.setBackgroundColor(getResources().getColor(R.color.white));
                    int height = imgContent.getHeight();
                    if (scrollY < height) {
                        int alpha = (int) (new Float(scrollY) / new Float(height) * 200);
                        Log.e("yy", "" + alpha);
                        llTitle.getBackground().mutate().setAlpha(alpha);
                        if (alpha < 150) {
                            mainTitleBar.setTitleText("");
                            mainTitleBar.setBackImageResource(R.drawable.white_back);
                            mainTitleBar.setMenuImageResource(R.drawable.image_diandia);
                        } else {
                            mainTitleBar.setTitleText("商品详情");
                            mainTitleBar.setBackImageResource(R.drawable.img_back);
                            mainTitleBar.setMenuImageResource(R.drawable.pic15);

                        }
                    } else {
                        llTitle.getBackground().mutate().setAlpha(255);
                    }

                }

            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }


    public void showData(String state) {
        if (state.equals("success")) {
            dataLayout.setVisibility(View.VISIBLE);
            noNetLayout.setVisibility(View.GONE);
        } else {
            dataLayout.setVisibility(View.GONE);
            noNetLayout.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void getData(CommodityDetailsBean bean) {

        this.bean = bean;
        if (bean.data.is_liked == 2) {
            isLike = true;
        } else {
            isLike = false;
        }
        if (bean.data.is_collectioned == 2) {
            isCollect = true;
        } else {
            isCollect = false;
        }
        Glide.with(BaseActivity.context)
                .load(bean.data.icon)
                .apply(MyApplication.options_no_transform)
                .into(imgContent);
        if (TextUtils.isEmpty(bean.data.video)) {
            myRadioGroup.setVisibility(View.GONE);
            videoItemPlayer.setVisibility(View.GONE);
            imgContent.setVisibility(View.VISIBLE);
            tvName.setVisibility(View.VISIBLE);
            tvLike.setVisibility(View.VISIBLE);
            tvCollect.setVisibility(View.VISIBLE);
            tvLook.setVisibility(View.VISIBLE);
        } else {
            imgContent.setVisibility(View.GONE);
            tvName.setVisibility(View.GONE);
            tvLike.setVisibility(View.GONE);
            tvCollect.setVisibility(View.GONE);
            tvLook.setVisibility(View.GONE);
            videoItemPlayer.setVisibility(View.VISIBLE);
            videoItemPlayer.setEnlargeImageRes(R.drawable.jz_enlarge);
            videoItemPlayer.setShrinkImageRes(R.drawable.jz_shrink);
            videoItemPlayer.setUp(bean.data.video, false, "");
            imageView = new ImageView(BaseActivity.context);
            //增加封面
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            Glide.with(BaseActivity.context)
                    .load(bean.data.video)
                    .into(imageView);
            videoItemPlayer.setThumbImageView(imageView);
            videoItemPlayer.getTitleTextView().setVisibility(View.GONE);
            videoItemPlayer.setIsTouchWiget(false);
            videoItemPlayer.setDismissControlTime(1500);
            videoItemPlayer.setBottomProgressBarDrawable(BaseActivity.context.getResources().getDrawable(R.drawable.video_new_progress));
            videoItemPlayer.setBottomShowProgressBarDrawable(BaseActivity.context.getResources().getDrawable(R.drawable.video_new_seekbar_progress), BaseActivity.context.getResources().getDrawable(R.drawable.video_new_seekbar_thumb));

            //设置返回键
            videoItemPlayer.getBackButton().setVisibility(View.GONE);

            //设置旋转
            orientationUtils = new OrientationUtils(this, videoItemPlayer);
            //设置全屏按键功能,这是使用的是选择屏幕，而不是全屏
            videoItemPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    resolveFullBtn(videoItemPlayer);
                }
            });
            autoPlay();
        }

//        tvContent.loadDataWithBaseURL("about:blank", bean.data.description, "text/html", "utf-8", null);
//        tvQuestion.loadDataWithBaseURL("about:blank", bean.data.help, "text/html", "utf-8", null);

        tvContent.loadUrl(URLS.HOST + "product/getDescription?id=" + getIntent().getStringExtra("id"));
        tvQuestion.loadUrl(URLS.HOST + "product/help");

        for (int i = 0; i < bean.data.image.size(); i++) {
            imgAdapter.add(bean.data.image.get(i).sm);
        }

        mAdapter.addAll(bean.data.comment);
        if (bean.data.comment == null || bean.data.comment.size() == 0) {
            tvMore.setText("暂无评论");
        } else {
            tvMore.setText("查看更多评论...");
        }
        tvLook.setText(bean.data.viewed + "");
        tvLike.setText(bean.data.likes + "");
        tvCollect.setText(bean.data.collection + "");
        tvName.setText(bean.data.name);

        showData("success");
    }

    @Override
    public void likeGoods() {
        commodityDetailsPresenter.like(id);
    }

    @Override
    public void commentLikeSuccess(int position) {
        CommodityDetailsBean.DataBean.CommentBean bean = mAdapter.getItem(position);
        bean.likes = bean.likes + 1;
        bean.is_liked = 2;
        mAdapter.notifyItemChanged(position, bean);
    }

    @Override
    public void LikeSuccess() {
        isLike = !isLike;
    }

    @Override
    public void onFail() {
        showData("fail");
    }

    @Override
    public void share() {
        ShareDialogUtils.showShareDialog(this, bean.data.dowload_app_link, bean.data.name, bean.data.icon, "优品日记", "11", shareListener);
    }

    @Override
    public void commentSuccess(GoodsCommentSuccessBean bean, int position) {
        List<CommodityDetailsBean.DataBean.CommentBean> list = new ArrayList<>();
        if (position == -1) {
            list.add(bean.data);
            list.addAll(mAdapter.getAllData());
            mAdapter.clear();
            mAdapter.addAll(list);
        } else {
            CommodityDetailsBean.DataBean.CommentBean.SubBean subBean = new CommodityDetailsBean.DataBean.CommentBean.SubBean();
            subBean.content = bean.data.content;
            subBean.nickname = BaseActivity.value.getUserNmae();
            subBean.portrait = BaseActivity.value.getHeadImg();

            CommodityDetailsBean.DataBean.CommentBean bean1 = mAdapter.getItem(position);
            bean1.sub.add(0, subBean);
            if (bean1.sub.size() >= 3) {
                bean1.more = 2;
            } else {
                bean1.more = 1;
            }
            mAdapter.notifyItemChanged(position);
        }
        if (mAdapter.getAllData() == null || mAdapter.getAllData().size() == 0) {
            tvMore.setText("暂无评论");
        } else {
            tvMore.setText("查看更多评论...");
        }

    }

    @Override
    public void CollectGoods() {
        commodityDetailsPresenter.collection(id);
    }

    @Override
    public void collectSuccess() {
        isCollect = !isCollect;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    private UMShareListener shareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
            SocializeUtils.safeShowDialog(dialog);
        }

        @Override
        public void onResult(SHARE_MEDIA platform) {
            SocializeUtils.safeCloseDialog(dialog);
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            SocializeUtils.safeCloseDialog(dialog);
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            SocializeUtils.safeCloseDialog(dialog);

        }
    };

    public void autoPlay() {
        if (BaseActivity.value.getAutoPlayVideo() == ColumValue.WIFI) {
            if (NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_WIFI) {
                videoItemPlayer.setNeedShowWifiTip(false);
                videoItemPlayer.startPlayLogic();
            } else {
                videoItemPlayer.setNeedShowWifiTip(true);
            }
        } else if (BaseActivity.value.getAutoPlayVideo() == ColumValue.NETWORK) {
            if (NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_WIFI || NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_3G || NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_2G || NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_WAP) {
                videoItemPlayer.setNeedShowWifiTip(false);
                videoItemPlayer.startPlayLogic();
            } else {
                videoItemPlayer.setNeedShowWifiTip(true);
            }
        } else if (BaseActivity.value.getAutoPlayVideo() == ColumValue.NO) {
            videoItemPlayer.setNeedShowWifiTip(true);
        }
    }

    @Override
    public void onBackPressed() {
        if (StandardGSYVideoPlayer.backFromWindowFull(this)) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onPause() {
        super.onPause();
        GSYVideoManager.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        GSYVideoManager.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        GSYVideoPlayer.releaseAllVideos();
        UMShareAPI.get(this).release();
    }

    /**
     * 全屏幕按键处理
     */
    private void resolveFullBtn(final StandardGSYVideoPlayer standardGSYVideoPlayer) {
        standardGSYVideoPlayer.startWindowFullscreen(context, true, true);
    }

    @OnClick({R.id.tv_more, R.id.ll_show_evaluation, R.id.btn_add_shopcart, R.id.btn_pay, R.id.no_net_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_more:
                intent = new Intent(BaseActivity.context, ReviewListActivity.class);
                intent.putExtra("id", getIntent().getStringExtra("id"));
                if (this.bean.data.is_liked == 1) {
                    intent.putExtra("isLike", false);
                } else {
                    intent.putExtra("isLike", true);
                }
                startActivity(intent);
                break;
            case R.id.ll_show_evaluation:
                commodityDetailsPresenter.showEvaluationDialog(id, "", -1);
                break;
            case R.id.btn_add_shopcart:
//                commodityDetailsPresenter.collection(id);
                if (BaseActivity.value.getIsLogin()) {
                    if (TextUtils.isEmpty(bean.data.links)) {
                        intent = new Intent(BaseActivity.context, EditOrderActivity.class);
                        intent.putExtra("id", id);
                        intent.putExtra("bean", bean);
                        intent.putExtra("isShare", isShare);
                        intent.putExtra("key", key);
                        startActivity(intent);
                    } else {
                        intent = new Intent(BaseActivity.context, WebViewActivity.class);
                        intent.putExtra("url", bean.data.links);
                        intent.putExtra("title", "详情");
                        startActivity(intent);
                    }

                } else {
                    intent = new Intent(BaseActivity.context, LoginActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.btn_pay:
                if (BaseActivity.value.getIsLogin()) {
                    if (TextUtils.isEmpty(bean.data.links)) {
                        intent = new Intent(BaseActivity.context, EditOrderActivity.class);
                        intent.putExtra("id", id);
                        intent.putExtra("bean", bean);
                        intent.putExtra("isShare", isShare);
                        intent.putExtra("key", key);
                        startActivity(intent);
                    } else {
                        intent = new Intent(BaseActivity.context, WebViewActivity.class);
                        intent.putExtra("url", bean.data.links);
                        intent.putExtra("title", "详情");
                        startActivity(intent);
                    }

                } else {
                    intent = new Intent(BaseActivity.context, LoginActivity.class);
                    startActivity(intent);
                }

                break;
            case R.id.no_net_btn:
                commodityDetailsPresenter.initData(getIntent().getStringExtra("id"));
                break;
        }
    }
}
